package util
{
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	public class RemoteObjectUtil
	{
		public function RemoteObjectUtil()
		{
			
		}
		/**
		 * 创建一个远程调用对象
		 * */
		public function createRemoteObject(destination:String,resultEvent:Function,faultEvent:Function):RemoteObject{
        	var ro:RemoteObject=new RemoteObject();
		  	ro.destination=destination;
		  	ro.addEventListener(ResultEvent.RESULT,resultEvent);		  
		  	if(!faultEvent){
		  		ro.addEventListener(FaultEvent.FAULT,faule);
		  	}	
           	return ro;
        }
         /**
		 * 错误处理方法
		 **/      
        private function faule(e:FaultEvent):void{
             	 Alert.show(e.message.toString());              
        }   
	}
}